﻿using UnityEngine;
using System.Collections;
using UnityEngine.UI;

public class ScoreSender : MonoBehaviour {
	string url="http://fischkoder.zz.mu/addscore.php";
	int fishqtd;
	string name;
	public GameObject sentMessage;
	
	// Use this for ini
	public void sendData(){
		StartCoroutine(postScore());
	}
	
	public void setData(int q, string n){
		fishqtd = q;
		name = n;
		sendData();
	}
	
	IEnumerator postScore() {
		WWWForm f = new WWWForm();
		f.AddField("fishes",fishqtd);
		f.AddField("name",name);
		sentMessage.GetComponent<Text>().text = "Wait...";
		WWW p = new WWW(url,f);
		yield return p;
		if(p.error != null) {
			print("There was an error posting the high score: " + p.error);
		}else{
			sentMessage.GetComponent<Text>().text = "Sent";
			//Show the score was sent
		}
	}
}